package com.zhizuobiao.controller;

import com.zhizuobiao.entity.Detail;
import com.zhizuobiao.entity.QueryUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;

@Controller
public class JsonController {

    @RequestMapping("/testjson")
    @ResponseBody
    // @RequestBody Detail detail
    // 提交的json数据封装到对象
    public Detail testJson(@RequestBody Detail detail) {

        System.out.println(detail);

        Detail detail2 = new Detail();
        detail2.setDescrption("hello json");
        detail2.setId(10);
        return detail2;
    }

    // https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete?access_token=ACCESS_TOKEN
    @RequestMapping("/user/batchdelete")
    @ResponseBody
    public String testJson2(@RequestBody QueryUser queryUser, HttpServletRequest request) {

        System.out.println(queryUser);

        Map parameterMap = request.getParameterMap();

        System.out.println("parameterMap=" + parameterMap.size());
        Set<Map.Entry> entrySet = parameterMap.entrySet();
        for (Map.Entry entry : entrySet) {
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
        }

        String[] testValue = request.getParameterValues("useridlist");

        System.out.println("getParameterValues =" + Arrays.toString(testValue));

        return queryUser.toString();
    }


    // https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete?access_token=ACCESS_TOKEN
    @RequestMapping("/user/batchdelete2")
    @ResponseBody
    public String testJson3(HttpServletRequest request) {


        Map parameterMap = request.getParameterMap();

        System.out.println("parameterMap=" + parameterMap.size());
        Set<Map.Entry> entrySet = parameterMap.entrySet();
        for (Map.Entry entry : entrySet) {
            System.out.println("key=" + entry.getKey());
            System.out.println("value=" + entry.getValue());
        }


        return "test";
    }
}
